package com.song.email.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

import com.song.email.core.EmailCenter;
import com.song.email.util.common.Config;
import com.song.email.util.common.Counter;

public class EmailServlet extends HttpServlet {
	private static final long serialVersionUID = 1118138246549134447L;

	public void init() throws ServletException {
		Counter.init();
		EmailCenter.getInstance().doWork();
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String maillist = request.getParameter("maillist");
		if(StringUtils.isNotBlank(maillist)){
			//重新加载文件.
			Config.mailtoList = maillist;
			EmailCenter.getInstance().loadEmailInfo();
			EmailCenter.getInstance().doWork();
		}
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
